module breathing_led(
	input clk_51200Hz,
	input[13:0] led_state,
	input flag,
	output reg[7:0] led_out
);

	parameter STATE4 = 7'd70;
	parameter STATE3 = 7'd35;
	parameter STATE2 = 7'd5;
	parameter STATE1 = 7'd1;
	
	reg[6:0] count = 7'd0;
	reg[13:0] temp_state = 14'd0;
	
	always @(posedge clk_51200Hz) begin
		
		if(flag == 1'b0) begin
			if(count <= STATE1) begin
				led_out = led_state[10:3];
			end
			else if(count <= STATE2) begin
				temp_state = ((led_state << 1) & led_state);
				led_out = temp_state[10:3];
			end
			else if(count <= STATE3) begin
				temp_state = ((led_state << 2) & led_state);
				led_out = temp_state[10:3];
			end
			else if(count <= STATE4) begin
				temp_state = ((led_state << 3) & led_state);
				led_out = temp_state[10:3];
			end
			else begin
				led_out = 8'd0;
			end
		end
		else begin
			if(count <= STATE1) begin
				led_out = led_state[10:3];
			end
			else if(count <= STATE2) begin
				temp_state = ((led_state >> 1) & led_state);
				led_out = temp_state[10:3];
			end
			else if(count <= STATE3) begin
				temp_state = ((led_state >> 2) & led_state);
				led_out = temp_state[10:3];
			end
			else if(count <= STATE4) begin
				temp_state = ((led_state >> 3) & led_state);
				led_out = temp_state[10:3];
			end
			else begin
				led_out = 8'd0;
			end
		end
		
		if(count == 7'd127) begin
			count = 7'd0;
		end
		else begin
			count = count + 7'd1;
		end
		
	end

endmodule
